<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\GoodsAttribute;
class Good extends Model
{
    use SoftDeletes;
    protected $casts = [
        'attachment' => 'json',
        'rattachment' => 'json',
        'parm' => 'json',
        'rparm' => 'json',
    ];

    public static $status = [ 1 => '上架', 0 => '下架'];
    public static $recommend = [ 0 => '无', 1 => '热销产品', 2 => '推荐产品', 3 => '最新产品'];


    public function setAttachmentAttribute($pictures)
    {
        if (is_array($pictures)) {
            $this->attributes['attachment'] = json_encode($pictures);
        }
    }

    public function getAttachmentAttribute($pictures)
    {
        return json_decode($pictures, true);
    }
    public function setRattachmentAttribute($pictures)
    {
        if (is_array($pictures)) {
            $this->attributes['rattachment'] = json_encode($pictures);
        }
    }

    public function getRattachmentAttribute($pictures)
    {
        return json_decode($pictures, true);
    }

    public function goods_attributes()
    {
        return $this->hasMany(GoodsAttribute::class, 'good_id');
    }

}
